package com.zcc.lesson04;

import com.zcc.lesson02.utils.JDBCUtils;
import com.zcc.lesson04.utils.DBCPUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class TestDBCP {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement ps = null;

        try{
            con = DBCPUtils.getConnection();

            //预编译可以使用?占位符来代替参数
            String sql = "delete from users where id = ?";
            ps=con.prepareStatement(sql);
            ps.setInt(1,5);

            int i = ps.executeUpdate();

            if (i>0){
                System.out.println("删除成功！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBCPUtils.release(con,ps,null);
        }
    }
}
